package com.marvels.financial.loan.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.financial.loan.dto.AnalysisStatisticalConditionDTO;
import com.marvels.financial.loan.dto.BorrowStaticDTO;
import com.marvels.financial.loan.dto.PaymentStaticDTO;
import com.marvels.financial.loan.service.FinanceStaticApi;

/**
 * 贷后管理-借款统计
 * @author 唐佩文
 *
 */
@Controller
@RequestMapping("financial/loan/financeStatic/service")
public class FinanceStaticController {
	
	@Autowired
	private FinanceStaticApi financeStaticApi;
	
	/**
	 * 贷后管理-借款统计
	 * @param conditionDTO
	 * @return
	 */
	@RequestMapping("/borrowStatic")
	@ResponseBody
	public MarvelsResultDTO borrowStatic(@RequestBody AnalysisStatisticalConditionDTO conditionDTO){
		try {
			List<BorrowStaticDTO> dataDTO=financeStaticApi.borrowStatic(conditionDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), dataDTO);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>查询贷后管理-借款统计FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), null);
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>查询贷后管理-借款统计异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), "查询贷后管理-借款统计异常", null);
		}
	}
	
	
	
	/**
	 * 贷后管理-还款统计
	 * @param conditionDTO
	 * @return
	 */
	@RequestMapping("/payentStatic")
	@ResponseBody
	public MarvelsResultDTO payentStatic(@RequestBody AnalysisStatisticalConditionDTO conditionDTO){
		try {
			List<PaymentStaticDTO> dataDTO=financeStaticApi.paymentStatic(conditionDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), dataDTO);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>查询贷后管理-还款统计FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), null);
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>查询贷后管理-还款统计异常", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), "查询贷后管理-还款统计异常", null);
		}
	}
}
